using NodeCanvas.Variables;
using UnityEngine;

namespace NodeCanvas.Actions
{
	[Category("Movement")]
	[AgentType(typeof(Transform))]
	public class RotateAway : ActionTask
	{
		[RequiredField]
		public BBGameObject target;

		public BBFloat speed;

		[SliderField(1f, 180f)]
		public BBFloat angleDifference = new BBFloat
		{
			value = 5f
		};

		public bool repeat;

		protected override void OnExecute()
		{
			Rotate();
		}

		protected override void OnUpdate()
		{
			Rotate();
		}

		private void Rotate()
		{
			if (Vector3.Angle(target.value.transform.position - base.agent.transform.position, -base.agent.transform.forward) > angleDifference.value)
			{
				Vector3 vector = target.value.transform.position - base.agent.transform.position;
				base.agent.transform.rotation = Quaternion.LookRotation(Vector3.RotateTowards(base.agent.transform.forward, vector, (0f - speed.value) * Time.deltaTime, 0f));
			}
			if (!repeat)
			{
				EndAction();
			}
		}
	}
}
